package com.itheima.stargraph.service;

import com.openai.client.OpenAIClient;
import com.openai.models.chat.completions.ChatCompletion;
import com.openai.models.chat.completions.ChatCompletionCreateParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * TODO
 *
 * @Author mr.wu
 * @Data #{DATE} #{TIME}
 */
@Component
public class OllamaService {

    @Autowired
    private OpenAIClient openAIClient;
    @Value("${ollama.model}")
    private String model;

    public String translation(String prompt){

        ChatCompletionCreateParams prarms = ChatCompletionCreateParams.builder()
                .addSystemMessage("你是一个专业的翻译助手，专注于中英互译。接下来用户提问的内容都要用英文回答！")
                .addUserMessage(prompt)
                .model(model)
                .build();
        ChatCompletion chatCompletion = openAIClient.chat().completions().create(prarms);
        String result = chatCompletion.choices().get(0).message().content().orElse(null);
        return result;
    }
}
